package com.mib.browser;

import com.ireasoning.util.MibTreeNode;

import javax.swing.table.AbstractTableModel;

public class PropertyTableModel extends AbstractTableModel {
    private MibTreeNode selectedMibTreeNode = null;
    String[] columnNames = new String[]{"Property", "Value"};

    public PropertyTableModel() {
    }

    public int getColumnCount() {
        return this.columnNames.length;
    }

    public int getRowCount() {
        return this.getSelectedMibTreeNode() == null ? 0 : 10;
    }

    public String getColumnName(int col) {
        return this.columnNames[col];
    }

    public Object getValueAt(int row, int col) {
        if (col == 0) {
            switch (row) {
                case 0:
                    return "Name";
                case 1:
                    return "OID";
                case 2:
                    return "Full Name";
                case 3:
                    return "Syntax";
                case 4:
                    return "Access";
                case 5:
                    return "Status";
                case 6:
                    return "Defval";
                case 7:
                    return "isIndexNode";
                case 8:
                    return "isV2Trap";
                case 9:
                    return "Description";
            }
        } else {
            switch (row) {
                case 0:
                    return this.selectedMibTreeNode.getName().toString();
                case 1:
                    return this.selectedMibTreeNode.getOID().toString();
                case 2:
                    return this.selectedMibTreeNode.getFullName();
                case 3:
                    return this.selectedMibTreeNode.getSyntax();
                case 4:
                    return this.selectedMibTreeNode.getAccess();
                case 5:
                    return this.selectedMibTreeNode.getStatus();
                case 6:
                    return this.selectedMibTreeNode.getDefVal();
                case 7:
                    return this.selectedMibTreeNode.isIndexNode();
                case 8:
                    return this.selectedMibTreeNode.isSnmpV2TrapNode();
                case 9:
                    return this.selectedMibTreeNode.getDescription();
            }
        }

        return null;
    }

    public Class getColumnClass(int c) {
        return this.getValueAt(0, c).getClass();
    }

    public boolean isCellEditable(int row, int col) {
        return false;
    }

    public void setValueAt(Object value, int row, int col) {
    }

    public void clearAll() {
        this.fireTableDataChanged();
    }

    public MibTreeNode getSelectedMibTreeNode() {
        return this.selectedMibTreeNode;
    }

    public void setSelectedMibTreeNode(MibTreeNode selectedMibTreeNode) {
        this.selectedMibTreeNode = selectedMibTreeNode;
        this.fireTableDataChanged();
    }
}
